package com.athuiju.hr.controller;



import com.athuiju.commonutils.R;
import com.athuiju.hr.entity.vo.AdministratorVo;
import com.athuiju.hr.entity.vo.AdministratorVoQuery;
import com.athuiju.hr.service.AdministratorService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wzh
 * @since 2022-01-12
 */
@Api(value="管理员administratorService",tags={"管理员操作接口"})
@RestController
@RequestMapping("/hr/administrator")
public class AdministratorController {
    @Autowired
    private AdministratorService administratorService;
    @ApiOperation(value = "根据条件分页查询管理员列表controller")
    @PostMapping("conditionAdmin/{page}/{limit}")
    @ApiResponses({@ApiResponse(code = 200,message = "OK",response = AdministratorVo.class),
    })
    public R pageQueryConditionAdmin(@ApiParam(name = "page", value = "当前页码", required = true)
                                 @PathVariable Long page,
                                 @ApiParam(name = "limit", value = "每页记录数", required = true)
                                 @PathVariable Long limit,
                                 @ApiParam(name = "AdministratorVoQuery", value = "条件查询对象", required = false)
                                 @RequestBody AdministratorVoQuery administratorVoQuery) {

        //创建page对象
    Page<AdministratorVo> pageSture = new Page(page, limit);
        //调用方法实现分页
        //调用方法的时候，底层封装，把分页所有的数据封装到pageSture里面
        administratorService.pageQuery(pageSture, administratorVoQuery);
        /* 取出数据封装 */
        //总记录数
        long total = pageSture.getTotal();
        //数据集合
        List<AdministratorVo> records = pageSture.getRecords();
        /* 页码大于1，且records为空或者records为0的时候，就让数据默认显示在第一页 */
        if(page>1){
            if(records==null || records.size()==0){
                Page<AdministratorVo> pageSture02=new Page(1,limit);
                administratorService.pageQuery(pageSture02,administratorVoQuery);
            }
        }
        return R.ok().data("total", total).data("page",page).data("limit",limit).data("rows", records);
    }

}

